package com.lvwenguo.controller.category;

import com.lvwenguo.service.CategoryListServiceInter;
import com.lvwenguo.service.serviceImple.CategoryListServiceImple;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//添加品类信息
@WebServlet(urlPatterns = "/AddCategory")
public class AddCategory extends HttpServlet {
    CategoryListServiceInter categoryListServiceImpol =new CategoryListServiceImple();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String categoryName = req.getParameter("categoryName");
        int i = categoryListServiceImpol.AddCategory(categoryName);
        if(i==0){
            req.setAttribute("error","信息重复");
            req.getRequestDispatcher("/view/category/category_add.jsp").forward(req,resp);
        }else{
           req.getRequestDispatcher("/CategoryListServlet").forward(req,resp);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
